#ifndef HTTPD_FS_H
#define HTTPD_FS_H

#include "lwip/apps/fs.h"

#ifdef __cplusplus
extern "C" {
#endif

#define HTTPD_FILE_DEFINE(name, _open, _read, _write, _close) \
    static void __attribute__((constructor)) _arduino_add_client_ ## _open(void) { \
        static httpd_fs_file _file;  \
        httpd_fs_add_file(&_file, name, _open, _read, _write, _close); \
    }

typedef struct _httpd_fs_file {
    struct _httpd_fs_file *next;
    const char *name;
    int (*open)(struct fs_file *file, const char *name, void **priv);
    int (*read)(struct fs_file *file, char *buffer, int count, void **priv);
    int (*write)(struct fs_file *file, const char *buffer, int count, void **priv);
    void (*close)(struct fs_file *file, void **priv);
} httpd_fs_file;

void httpd_fs_add_file(httpd_fs_file *file, const char *name, 
        int (*open)(struct fs_file *file, const char *name, void **priv),
        int (*read)(struct fs_file *file, char *buffer, int count, void **priv),
        int (*write)(struct fs_file *file, const char *buffer, int count, void **priv),
        void (*close)(struct fs_file *file, void **priv));

#ifdef __cplusplus
}
#endif

#endif
